package Value类型

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object sortBy {

    def main(args: Array[String]): Unit = {

        val config: SparkConf = new SparkConf().setMaster("local[*]").setAppName("WordCount")

        val sc = new SparkContext(config)

        val rdd = sc.parallelize(List(3, 2, 4, 5, 1, 9, 8, 7, 6, 10), 4)

        println("排序前分区数" + rdd.partitions.size)
        rdd.glom().collect().foreach(array => {
            println(array.mkString(","))
        })

        val sortRDD: RDD[Int] = rdd.sortBy(x => x)//默认分区数不变、升序

        println("排序后分区数" + sortRDD.partitions.size)
        sortRDD.glom().collect().foreach(array => {
            println(array.mkString(","))
        })

        val sortRDD2: RDD[Int] = sortRDD.sortBy(x => x, false, 1)
        println("降序后分区数" + sortRDD2.partitions.size)
        sortRDD2.glom().collect().foreach(array => {
            println(array.mkString(","))
        })


    }

}
